package borderPatrol.Calculators;

import borderPatrol.Data.Move;
import borderPatrol.misc.CFRInformationSet;

public class BPProbabilityCalculator extends ProbabilityCalculator {

	@Override
	public void updateProbabilities(int iteration) {
		update("1", 1);
		update("2", 1);
	}
	
	private void update(String id, float probability) {
		
		CFRInformationSet set =  gameTree.get(id);
		int counter = 0;
		
		set.setProbabilityOfOccurence(probability);
		set.addProbabilityToSum();
	
		if(set.getIsTerminal() != 0) {
			return;
		}
		
		for (Move move : set.getMoves()) {
			update(getIdWithMove(id, move), probability*set.getStrategy()[counter++]);
		}
	}

	private String getIdWithMove(String id, Move move) {
		
		StringBuilder builder = new StringBuilder();
		
		builder.append(id);
		builder.append(".");
		builder.append(move);
		
		return builder.toString();
	}

}
